# -*- coding: UTF-8 -*-
import csv
import json
import os
import tempfile

import web
from web import form

urls = (
    '/upload', 'upload',
)

fileUpLoadFrom = form.Form(
    form.File('myfile', description="请选择要上传的文件"),
    form.Button('button', description="提交"),
)

from aip import AipOcr

""" 你的 APPID AK SK """
APP_ID = '11322449'
API_KEY = 'EVyjdsDGim5jlRAPSf1wVAv5'
SECRET_KEY = 'eYXPid0PvAL9FK7BeCSylGd0lyEVj348'

client = AipOcr(APP_ID, API_KEY, SECRET_KEY)


class upload:
    def GET(self):
        return """<html><head></head><body>
                    <form method="POST" enctype="multipart/form-data">
                    <input type="file" name="myfile" />
                    <br/>
                    <input type="submit" name="提交"/>
                    </form>
                    </body></html>"""

    def POST(self):
        fp = r'/'
        fn = "table.jpg"
        web.header('Content-Type', "csv")  # file type
        web.header('Content-disposition', 'attachment; filename=abc.csv')  # force browser to show "Save as" dialog.
        return "kokoko"  # your blob
        # return f'<html><head></head><body> <a href="{fp}" download="{fn}" >downLoadResult</a> </body></html>'


if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
